<?php
/////////////////////////////////////////////////////////////////////////////
// 这个文件是 网城创想多用户商城 项目的一部分
//
// Copyright (c) 2007 - 2008 www.shopnc.net
//
// 要查看完整的版权信息和许可信息，请查看源代码中附带的 COPYRIGHT 文件，
// 或者访问 http://www.shopnc.net/ 获得详细信息。
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : member.php   FILE_PATH : D:\webroot\mulitishop\member\member.php
 * ....会员管理会员资料
 *
 * @copyright Copyright (c) 2007 - 2007 www.shopnc.net 
 * @author 网城创想多用户商城开发团队 php_netproject@yahoo.com.cn
 * @package 
 * @subpackage 
 * @version Sat Aug 11 10:58:41 CST 2007
 */

require ("../global.inc.php");
class OwnMemberManage extends SystemFrameWork{
	/**
	 * 会员对象
	 *
	 * @var obj
	 */
	var $objmember;
	/**
	 * 验证对象
	 *
	 * @var obj
	 */
	var $objvalidate;

	function main(){
		/**
		 * 创建会员对象
		 */
		if (!is_object($this->objmember)){
			require_once ("member.class.php");
			$this->objmember = new MemberClass();
		}
		/**
		 * 创建验证对象
		 */
		if (!is_object($this->objvalidate)){
			require_once("commonvalidate.class.php");
			$this->objvalidate = new CommonValidate();
		}

		/**
		 * 设置模板路径
		 */
		$this->setsubtemplates("system");
		/**
		 * 语言包
		 */
		$this->getlang("member");
		/**
		 * 执行操作
		 */
		switch($this->_input['action']){
			case "modify":
				$this->_getModiBaseInfo();
				break;
			case "modifysave":
				$this->_saveModifyBaseInfo();
				break;
			case "lock":
				$this->_lockMember();
				break;
			case "unlock":
				$this->_unlockMember();
				break;
			case "del":
				$this->_delMember();
				break;
			case "add":
				$this->_addMember();
				break;
			case "addsave":
				$this->_addsaveMember();
				break;
			default:
				$this->_getListInfo();
				break;
		}

	}

	/**
	 * 得到会员列表
	 *
	 */
	function _getListInfo(){
		/**
		 * 初始化分页类
		 */
		require_once("commonpage.class.php");
		$obj_page = new CommonPage();

		/**
		 * 取得会员列表
		 */
		$obj_page->pagebarnum(20);
		$member_array = $this->objmember->getMemberList($this->_input,$obj_page);
		foreach ($member_array as $k=>$v){
			$member_array[$k]['state'] = $this->_b_config['memberstate'][$member_array[$k]['member_state']];
		}
		$page_list = $obj_page->show(1);
		/**
		 * 输出到页面模板
		 */
		$this->output("page_list", $page_list);
		$this->output("member_array",$member_array);
		$this->showpage("sys_member.list");

	}
	/**
	 * 得到会员的基本信息
	 *
	 */
	function _getModiBaseInfo(){
		/**
		 * 得到会员资料
		 */
		$member_array = $this->objmember->getMemberInfo($this->_input['member_id']);
		/**
		 * 性别单选框
		 * 默认选中男性
		 */
		if ($member_array['gender']==""){
			$member_array['gender'] = "m";
		}
		$this->output("gender" , Common::showForm_Radio("rdoGender","",$this->_b_config['gender'],$member_array['gender']));
		$this->output('member_array',$member_array);
		$this->showpage("sys_member.modi");
	}

	/**
	 * 修改会员基本资料
	 *
	 */
	function _saveModifyBaseInfo(){
		/**
		 * 验证提交的表单
		 */
		$this->objvalidate->setValidate(array("input"=>$this->_input['txtemail'],"require"=>"true","validator"=>"Email","message"=>$this->_lang['errMEmail_Wrong']));    //请输入正确格式的email!
		//print_r($this->objvalidate->validateparam);
		$error = $this->objvalidate->validate();
		if($error != ""){
			echo $error;
		}else{
			$this->objmember->modifyMember($this->_input,$this->_input['member_id']);
		}

	}
	
	/**
	 * 锁定会员
	 *
	 */
	function _lockMember(){
		$this->objmember->lockMember($this->_input['member_id']);
	}
	
	/**
	 * 开启会员
	 *
	 */
	function _unlockMember(){
		$this->objmember->unlockMember($this->_input['member_id']);
	}
	
	function _delMember(){
		$this->objmember->delMember($this->_input['member_id']);
	}
	/**
	 * 新增会员
	 *
	 */
	function _addMember(){
		$this->showpage('sys_member.add');
	}
	/**
	 * 吧新增会员信息放入数据库中
	 *
	 */
	function _addsaveMember(){
		$this->objvalidate->setValidate(array("input"=>$this->_input['txtloginname'],"require"=>"true","validator"=>"Length","min"=>5,"max"=>20,"message"=>$this->_lang['alertEnterUserName']));   //5-20个字符(包括小写字母、数字、下划线、中文)，一个汉字为两个字符，推荐使用中文会员名。一旦注册成功会员名不能修改。
		$this->objvalidate->setValidate(array("input"=>$this->_input['txtPassword'],"require"=>"true","validator"=>"Length","min"=>6,"max"=>16,"message"=>$this->_lang['alertEnterPassword']));    //密码由6-16个字符组成，请使用英文字母加数字或符号的组合密码，不能单独使用英文字母、数字或符号作为您的密码。		
		$this->objvalidate->setValidate(array("input"=>$this->_input['txtemail'],"require"=>"true","validator"=>"Email","message"=>$this->_lang['errMEmail_Wrong']));    //请输入正确格式的email!				
		$error = $this->objvalidate->validate();
		if ($error != "" ){
			$this->redirectPath("error","",$error);
		}else{
			if ($this->objmember->checkMemberExist($this->_input['txtloginname']) == true){
				$this->redirectPath("error","","会员已经存在");
			}else if($this->objmember->checkMemberExist($this->_input['txtemail'],"email") == true){
				$this->redirectPath("error","","邮箱已被注册过");
			}else{
				$this->objmember->addMember($this->_input);	
				//$this->redirectPath("common","home/member.php?action=login","");
			}
		}
	}
}
$member = new OwnMemberManage();
$member->main();
unset($member);
?>